package parser.nodes;

// RepreatStatement = 'REPEAT' StatementSequence 'UNITL' Expression
import codegen.CodeGen;

public class RepeatStatementNode extends Node {

	private StatementSequenceNode stmts;
	private ExpressionNode condition;

	public RepeatStatementNode(StatementSequenceNode stmts, ExpressionNode condition) {
		this.stmts = stmts;
		this.condition = condition;
	}

	@Override
	public void print() {
		p("RepeatStatement:");
		indent();
		p("REPEAT");
		stmts.print();
		p("UNTIL");
		condition.print();
	}

	@Override
	public void abstractPrint() {
		p("REPEAT");
		indent();
		condition.abstractPrint();
		stmts.abstractPrint();
		unindent();
	}

	@Override
	public void compile(CodeGen c) throws CompileError {
		int startlabel = c.getLabel();
		int afterlabel = c.getLabel();
		c.outstr("LABEL, " + startlabel);
		stmts.compile(c);
		condition.compile(c);
		c.outstr("BT, " + afterlabel);
		c.outstr("JMP, " + startlabel);
		c.outstr("LABEL, " + afterlabel);


	}
}
